<?php
session_start();
?>


<?php
ini_set('session.bug_compat_warn', 0);
ini_set('session.bug_compat_42', 0);

$username = $_SESSION['username'];
if($username==null || $username== ""|| $username == "")
{
	header('Location: http://172.26.195.159/checklist/php/logout.php');
}
?>

<?php require_once('KLogger.php');
$log = new KLogger ( "log.txt" , KLogger::DEBUG );
?>


<!--  Starting the code to submit the details in the table -->

<!----- NAMES WIL BE PUBLISHED HERE TO BE STORED IN DB -->

<?php

//Fetching the variables

$designer=$_REQUEST['designer'];

$id = $_REQUEST['id'];
$role = $_SESSION['role'];

$title = $_REQUEST['title'];
$description = $_REQUEST['description'];
$design_note_reqd = $_REQUEST['design_note_reqd'];
$root_cause = $_REQUEST['root_cause'];
$solution = $_REQUEST['solution'];
$view_name = $_REQUEST['view_name'];
$activity_name = $_REQUEST['activity_name'];
$patch_back_reqd = $_REQUEST['patch_back_reqd'];
$patch_name = $_REQUEST['patch_name'];
$parcel_name = $_REQUEST['parcel_name'];
$compile_dir = $_REQUEST['compile_dir'];
$package_dir = $_REQUEST['package_dir'];
$build_target = $_REQUEST['build_target'];
$checklist_reviewer = $_REQUEST['checklist_reviewer'];
$pl = $_REQUEST['pl'];
$pm =  $_REQUEST['pm'];
$patching_guidelines =  $_REQUEST['patching_guidelines'];
$dp_prime =   $_REQUEST['dp_prime'];
$baseline =  $_REQUEST['baseline'];
$milestone =  $_REQUEST['milestone'];
$complexity =  $_REQUEST['complexity'];
$line_of_code  =  $_REQUEST['line_of_code'];
$domain = $_REQUEST['domain'];
$internal_idce_number = $_REQUEST['internal_idce_number'];
$internal_idce_reviewer = $_REQUEST['internal_idce_reviewer'];
$external_idce_reqd = $_REQUEST['external_idce_reqd'];
$external_idce_number = $_REQUEST['external_idce_number'];
$external_idce_reviewer = $_REQUEST['external_idce_reviewer'];


//Adding the variables to the session.
$_SESSION['id'] = $id;
$_SESSION['external_idce_reqd'] = $external_idce_reqd;



if($external_idce_reqd == "No")
{
$external_idce_number = 0;
$external_idce_reviewer = 'selectName';
}

//creating a connection.

$con = mysql_connect("localhost","root","");

mysql_select_db("checklist", $con);

//Creating escaped Strings : 20/02/2012 
$title_escaped = mysql_real_escape_string($title);
$description_escaped = mysql_real_escape_string($description);
$root_cause_escaped = mysql_real_escape_string($root_cause);
$solution_escaped = mysql_real_escape_string($solution);

//check if same CR ID already exists in database.

$check = "select * from cr where id = '$id' ";
$result = mysql_query($check);
if(mysql_num_rows($result))
{
echo '<script type="text/javascript">','alert("Sorry , CR Id already exists.");',
'window.location = "http://172.26.195.159/checklist/php/crdetails.php";' ,'</script>';
}

else
{
//insert in cr
$sql_1 = "insert into cr values('$username' , '$id' , '$title_escaped' , '$description_escaped' , '$design_note_reqd' , '$root_cause_escaped' , '$solution_escaped' , '$view_name' , '$activity_name' , '$patch_back_reqd' , '$patch_name' , '$parcel_name' , '$compile_dir'
, '$package_dir' , '$build_target' , '$checklist_reviewer' , '$pl' , '$pm' , '$patching_guidelines' ,'$dp_prime'  , '$baseline' , '$milestone' , '$complexity' , $line_of_code , '$domain' ,$internal_idce_number , '$internal_idce_reviewer' , '$external_idce_reqd' , $external_idce_number , '$external_idce_reviewer')";

mysql_query($sql_1,$con) or die('Error: ' . mysql_error());


//insert in cr_status
$sql_2 = "insert into cr_status values('$id' , CURDATE() , '' , '$username', '$checklist_reviewer' , '$dp_prime', '$internal_idce_reviewer', '$external_idce_reviewer' , '$pl' , '$pm' , 0)";

mysql_query($sql_2,$con) or die('Error: ' . mysql_error());
  
$log->logInfo('In processCrDetails[101] : '.$id);
}
echo '<script type="text/javascript">','alert("Query Successfully Submitted.");',
'window.location = "http://172.26.195.159/checklist/php/mainpage.php";' ,'</script>';
	

?>

